# Importing Data
UKRAINE<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "G1:G264")

# Checking the Imported Data
View(UKRAINE)
# Creating Time Series Data
UKRAINE_ts <- ts(UKRAINE, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
UKRAINE_ts
sum(is.na(UKRAINE_ts))
library(forecast)
UKRAINE_ts <- tsclean(UKRAINE_ts)
UKRAINE_ts

# Identification: Plotting the Time Series Data
plot(UKRAINE_ts)

# Estimating the appropriate model
UKRAINE_ts_model <- auto.arima(UKRAINE_ts)
UKRAINE_ts_model

# Forecasting
options(max.print=1000000)
UKRAINE_ts_forecast <- forecast (UKRAINE_ts_model, level=c(95), h=264)
plot(UKRAINE_ts_forecast)
UKRAINE_ts_forecast             

# Exporting
write.table(UKRAINE_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/UKRAINE_TSA.csv", sep=",")
